#!/usr/bin/env python3
"""
快速计算电话号码对应的分片表
"""

import mmh3
import sys

def get_table_index(phone):
    """使用MurmurHash3基于phone进行分表"""
    if not phone:
        return 0
    hash_value = mmh3.hash(str(phone))
    return abs(hash_value) % 200

if __name__ == "__main__":
    # 测试号码
    phones = ["13600005769", "13600008583"]
    
    if len(sys.argv) > 1:
        phones = sys.argv[1:]
    
    print("=" * 60)
    print("MurmurHash3 分片表计算")
    print("=" * 60)
    
    for phone in phones:
        hash_value = mmh3.hash(str(phone))
        table_index = get_table_index(phone)
        
        print(f"\n电话号码: {phone}")
        print(f"  Hash值: {hash_value}")
        print(f"  表索引: {table_index}")
        print(f"  目标表: data_{table_index}")
    
    print("\n" + "=" * 60)

